-------------------------------------------------------------------------------
-- Title      : decodeSeg7.vhd
-- Project    : lab 5
-------------------------------------------------------------------------------
-- File       : decodeSeg7.vhd
-- Author     : Paul Winslow
-- Company    : 
-- Created    : 2012-09-15
-- Last update: 2012-11-24
-- Platform   : 
-- Standard   : VHDL'93
-------------------------------------------------------------------------------
-- Description: Decodes a 4 bit input to an 8 bit output for a 7-segment led
--              number display. The decimal point is [7]. This block outputs
--              hex numbers for the Nexys 7-segs and binary decoder-type
--              output (for fun and profit).
--              
--              Note: This block controls the cathode array.
--                    anode <= '0' and cathode <= '0' for the segment to work.
--                    The 'anode' controls a pnp that enables the +3.3v rail
--                    for a given digit when pulled low.
--                    The 'cathode' sinks the current to turn a segment on. 
--              
--              In   : Hex : Out_hex  : Out_bin
--              0000 : 0   : 11000000 : 1111111111111110
--              0001 : 1   : 11111001 : 1111111111111101
--              0010 : 2   : 10100100 : 1111111111111011
--              0011 : 3   : 10110000 : 1111111111110111
--              0100 : 4   : 10011001 : 1111111111101111
--              0101 : 5   : 10010010 : 1111111111011111
--              0110 : 6   : 10000010 : 1111111110111111
--              0111 : 7   : 11111000 : 1111111101111111
--              1000 : 8   : 10000000 : 1111111011111111
--              1001 : 9   : 10010000 : 1111110111111111
--              1010 : A   : 10001000 : 1111101111111111
--              1011 : b   : 10000011 : 1111011111111111
--              1100 : C   : 11000110 : 1110111111111111
--              1101 : d   : 10100001 : 1101111111111111
--              1110 : E   : 10000110 : 1011111111111111
--              1111 : F   : 10001110 : 0111111111111111
--                           HGFEDCBA
--              
--               __        A 
--              |__|     F G B   
--              |__|.    E D C  H
-------------------------------------------------------------------------------
-- Copyright (c) 2012 
-------------------------------------------------------------------------------
-- Revisions  :
-- Date        Version  Author  Description
-- 2012-09-15  1.0      paul    Created
-------------------------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;

package decodeSeg7_CMP is
  component decode7Seg
    port (
      in_bin  : in  std_logic_vector(3 downto 0);
      out_bin : out std_logic_vector(15 downto 0);
      out_dec : out std_logic_vector(7 downto 0));
  end component;
end decodeSeg7_CMP;

library ieee;
use ieee.std_logic_1164.all;

entity decode7Seg is
  
  port (
    in_bin  : in  std_logic_vector(3 downto 0);
    out_bin : out std_logic_vector(15 downto 0);
    out_dec : out std_logic_vector(7 downto 0));

end decode7Seg;

architecture behave of decode7Seg is

begin  -- behave

  -- Hex number output for the Nexys2 7 segment
  with in_bin select
    out_dec <= "11000000" when "0000",  -- 0
    "11111001"            when "0001",  -- 1
    "10100100"            when "0010",  -- 2
    "10110000"            when "0011",  -- 3
    "10011001"            when "0100",  -- 4
    "10010010"            when "0101",  -- 5
    "10000010"            when "0110",  -- 6
    "11111000"            when "0111",  -- 7
    "10000000"            when "1000",  -- 8
    "10010000"            when "1001",  -- 9
    "10001000"            when "1010",  -- A (10) 
    "10000011"            when "1011",  -- b (11)
    "11000110"            when "1100",  -- C (12)
    "10100001"            when "1101",  -- d (13)
    "10000110"            when "1110",  -- E (14)
    "10001110"            when "1111",  -- F (15)
    "10111111"            when others;

  -- Binary decoder output if desired
  with in_bin select
    out_bin <= "1111111111111110" when "0000",
    "1111111111111101"            when "0001",
    "1111111111111011"            when "0010",
    "1111111111110111"            when "0011",
    "1111111111101111"            when "0100",
    "1111111111011111"            when "0101",
    "1111111110111111"            when "0110",
    "1111111101111111"            when "0111",
    "1111111011111111"            when "1000",
    "1111110111111111"            when "1001",
    "1111101111111111"            when "1010",
    "1111011111111111"            when "1011",
    "1110111111111111"            when "1100",
    "1101111111111111"            when "1101",
    "1011111111111111"            when "1110",
    "0111111111111111"            when "1111",
    "1111111111111111"            when others;
  
end behave;
